/*******************************************************************************
 * This file is part of blueprint4j www.blueprint4j.org.
 * 
 *     blueprint4j is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     blueprint4j is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with blueprint4j. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package blueprint4j.db.utils;

/**
 * This class serves as a schedular for scheduable entities
 */

import java.sql.*;
import java.io.*;
import java.util.*;

import blueprint4j.db.*;
import blueprint4j.utils.*;


public class SchedularLog extends Entity {

	static String VERSION = "$Id: SchedularLog.java,v 1.4 2004/09/09 11:07:54 jaspervdb Exp $";

	public static final String TABLE_NAME = "d_schedular_logs";
	public TableName table_name = new TableName(TABLE_NAME,this);
	public FieldAutoId schedular_log_id = new FieldAutoId("id", 0, "The Record Identifier", this);
	
	public FieldGroup group_log = new FieldGroup("Schedule Run Log",this);
	public FieldBoolean run_ok = new FieldBoolean("run_ok",Field.FIELD_NAME,"Executed Correctly",this);
	public FieldText result = new FieldText("result",0,"Result of run",this);
	public FieldTimestamp runtime = new FieldTimestamp("runtime",Field.FIELD_NAME,"Execute Time",this);
	
	public FieldGroupDisable disable = new FieldGroupDisable(this);
	public FieldForeignKey schedular_id = new FieldForeignKey("schedular_id",0,"SchedularLog",26,SchedularLog.class,this);

	private Maintenance maintenance = new Maintenance(this,new Maintenance.Action[]{new Maintenance.ActionTrim(5000)},60*1000*60*5);

	public SchedularLog() {}

	public SchedularLog(DBConnection connection,Schedular schedular,String result) 
	throws SQLException {
		super(connection);
		schedular_id.set(schedular.id.getAsString());
		run_ok.set(new Boolean(true));
		this.result.set(result);
	}

	public SchedularLog(DBConnection connection,Schedular schedular,Throwable result) 
	throws SQLException {
		super(connection);
		schedular_id.set(schedular.id.getAsString());
		run_ok.set(new Boolean(false));
		this.result.set(result);
	}

	public Entity getNewInstance() {
		return new SchedularLog();
	}

}
